<template>
  <el-container class="home-container">
    <!-- 左侧导航区域 -->
    <el-aside width="200px">
      <div class="logo">
        <img src="../assets/zz-logo.png" alt />
        <span>后台管理系统</span>
      </div>
      <el-menu
        background-color="#323a4b"
        text-color="#fff"
        active-text-color="#169bd5"
        router
        unique-opened
        :default-active="activePath"
      >
        <el-submenu index="1">
          <template slot="title" background-color="#323A4B">
            <i class="el-icon-map-location"></i>
            <span>急救地图</span>
          </template>
          <el-menu-item index="/resource" @click="activeIndex('/resource')">
            <template slot="title">
              <i class="el-icon-caret-right"></i>
              <span>资源管理</span>
            </template>
          </el-menu-item>
          <el-menu-item index="/site" @click="activeIndex('/site')">
            <template slot="title">
              <i class="el-icon-caret-right"></i>
              <span>站点管理</span>
            </template>
          </el-menu-item>
          <el-menu-item index="/label" @click="activeIndex('/label')">
            <template slot="title">
              <i class="el-icon-caret-right"></i>
              <span>标签管理</span>
            </template>
          </el-menu-item>
        </el-submenu>
        <el-submenu index="2">
          <template slot="title">
            <i class="el-icon-first-aid-kit"></i>
            <span>急救自学</span>
          </template>
          <el-menu-item index="/official" @click="activeIndex('/official')">
            <template slot="title">
              <i class="el-icon-caret-right"></i>
              <span>官方信息发布</span>
            </template>
          </el-menu-item>
          <el-menu-item index="/mission" @click="activeIndex('/mission')">
            <template slot="title">
              <i class="el-icon-caret-right"></i>
              <span>急救宣教</span>
            </template>
          </el-menu-item>
        </el-submenu>
        <el-submenu index="3">
          <template slot="title">
            <i class="el-icon-s-order"></i>
            <span>公告管理</span>
          </template>
          <el-menu-item index="/announcement" @click="activeIndex('/announcement')">
            <template slot="title">
              <i class="el-icon-caret-right"></i>
              <span>公告管理</span>
            </template>
          </el-menu-item>
        </el-submenu>
        <el-submenu index="4">
          <template slot="title">
            <i class="el-icon-s-marketing"></i>
            <span>数据字典</span>
          </template>
          <el-menu-item index="/dataDictionary" @click="activeIndex('/dataDictionary')">
            <template slot="title">
              <i class="el-icon-caret-right"></i>
              <span>数据字典</span>
            </template>
          </el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-container>
      <!-- 头部区域 -->
      <el-header>
        <div class="user">
          <img src="../assets/navImg/默认头像.png" alt />
          <span>{{username}}</span>
        </div>
      </el-header>
      <!-- 主体区域 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      // 被激活的链接地址
      activePath: '',
      // 用户名
      username: '',
    }
  },
  created() {
    this.activePath = window.sessionStorage.getItem('activePath')
    this.getUrlParam('BQTOKEN')
    this.getUrlParam('BQUSERID')
    this.getUrlParam('BQAPPID')
    this.getUrlParam('username')
    this.username = this.getUrlParam('username')
    // console.log(this.getUrlParam('BQTOKEN'))
    window.sessionStorage.setItem('token', '1bfc616b0ec34898b9cf9e09a6a8cbb4')
    window.sessionStorage.setItem('userId', 'L8Dpu%2Bw2wmArl%2BBfyAMjTYj84jY8iM99vC%2F6F3cPZw8ikd9B2nCMpbbYx4gWOEkc')
    window.sessionStorage.setItem('appId', '200512144624483746')

    // let urlConfig = [
    //   {
    //     ip: '172.17.135.169',
    //     url: 'http://172.17.135.87:9999',
    //   },
    //   {
    //     ip: '59.207.61.2',
    //     url: 'http://59.207.61.2:10015',
    //   },
    //   {
    //     ip: '59.207.51.2',
    //     url: 'http://59.207.51.2:10015',
    //   },
    // ]
    // let reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/
    // let URL_HTTP = urlConfig.find((item) => item.ip === reg.exec(window.location.href)[0]).url

    // window.sessionStorage.setItem('token', this.getUrlParam('BQTOKEN'))
    // window.sessionStorage.setItem('userId', this.getUrlParam('BQUSERID'))
    // window.sessionStorage.setItem('appId', this.getUrlParam('BQAPPID'))
    // if (!this.getUrlParam('BQTOKEN')) {
    //   return (window.location = URL_HTTP)
    // }
  },
  methods: {
    // 保存链接的激活状态
    activeIndex(activePath) {
      // console.log(activePath)
      window.sessionStorage.setItem('activePath', activePath)
    },
    // 获取网址上的参数
    getUrlParam(name) {
      let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
      let result = window.location.search.substr(1).match(reg)
      return result ? decodeURIComponent(result[2]) : null
    },
  },
}
</script>
<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-aside,
.el-main {
  height: 100%;
}
.el-aside {
  background-color: #323a4b;
  .logo {
    height: 60px;
    background-color: #091b37;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    img {
      width: 35px;
      height: 35px;
    }
    span {
      font-size: 18px;
      font-family: PingFangSC-Semibold;
      color: #fff;
      margin-left: 15px;
    }
  }
  .el-menu-item {
    background-color: #222834 !important;
  }
}
.el-header {
  background-color: #091b37;
  .user {
    float: right;
    line-height: 60px;
    cursor: pointer;
    img {
      width: 30px;
      height: 30px;
      vertical-align: middle;
    }
    span {
      margin: 0 10px;
      color: #fff;
    }
  }
}
.el-main {
  background-color: #f0f2f5;
  // padding: 0px;
}
.el-menu {
  border-right: 0px;
}
</style>
